package wrap_text;

require Exporter;


our @ISA = qw(Exporter);
our $VERSION = 1.00;
our @EXPORT = qw( wrap_text);
use strict;
use warnings;
use Carp;
use Text::Wrap;

sub wrap_text
{
	my ($message, $indent, $hanging, $line_length, $sentinel) = @_;
	die "Too many parameters" if (defined $sentinel);
	$indent		||= "        ";
	$hanging	||= '  ';
	$line_length ||= 80;
	
	$Text::Wrap::columns = $line_length;
	$Text::Wrap::unexpand = 0;

	# find any tabs or spaces at the beginning of the text to be wrapped
	my $prefix = "";
	if ($message =~ /^([ \t]+)/)
	{
		$prefix = $1;
	}
	
	$message = Text::Wrap::wrap($indent, 		# beginning of first line
								$indent.$prefix.$hanging, 
								$message);
	return $message;
}


